﻿using UnityEngine;
using System.Collections;

public class moveGUItex : MonoBehaviour
{
	
	// Use this for initialization
	public Texture swipeTexture;
	public Texture tapTexture;
	public float swipeX = 10f;
	public float swipeY = 70f;
    public float tapX = 10f;
    public float tapY = 70f;
    public float swipeWidth = 40f;
    public float swipeHeight = 70f;
    public float tapWidth = 40f;
    public float tapHeight = 70f;
	public float horizontalMove = 0;
    public float horiztonalSpeed = 100f;
	public float verticalMove = 0;
    public bool onlyOnce = false;
	public bool swipeMe;
	public bool tapMe;
	public float timer;

    public static bool isToolTips = true;
    public Rect toolTipLoc;
    public Texture2D toolTipTexture;
    public string toolTipText;

    private bool isSound = false;
    public Rect soundLoc;
    public Texture2D soundTexture;
    public string soundText;

    public Rect creditsLoc;
    public Texture2D creditsTexture;
    public string creditsText;
    public GUIStyle style, soundStyle;
    public GUIStyle creditsStyle;
    void Start ()
	{
        GameCenterSingleton.Instance.Initialize();
        isSound = Manager.Sound;
		timer = 0;
        onlyOnce = true;
	}
	
	// Update is called once per frame
	void Update ()
	{
		
		timer += Time.deltaTime;
		if(timer >5 && timer < 12){
			swipeMe = true;
				horizontalMove += Time.deltaTime * horiztonalSpeed; // 100 px per second
		
		}
		if(timer > 12){
			swipeMe = false;
		}
		if(timer > 14){
			
			tapMe = true;
			verticalMove += Time.deltaTime * 100;
			if(timer > 20){
			tapMe = false;
			}
		}
	
	}
		
	void OnGUI ()
    {
        if (onlyOnce)
        {
    

            onlyOnce = false;
        }

		if(!StartGame.gameStart)
        {
			if(swipeMe){
	        GUI.DrawTexture(new Rect(swipeX + horizontalMove, Screen.height/swipeY, Screen.width/swipeWidth, Screen.height/swipeHeight), swipeTexture);
			}
		
			if(horizontalMove>Screen.width/2 - 40)
	        {
	            horizontalMove = 0;
	            swipeX = 100;
	            //swipeX = 0;
				//swipeTexture = null;
			}
			
	        //if(swipeTexture == null){
				if(tapMe){
						GUI.DrawTexture(new Rect(tapX, Screen.height/tapY + Mathf.PingPong( verticalMove + 400, 20), Screen.width/tapWidth, Screen.height/tapHeight), tapTexture);
			}
	        //}
			// GUI.DrawTexture(new Rect( Mathf.PingPong(10 + X1 ,2), Y1, Width, Height), myTexture1, ScaleMode.ScaleToFit,drawMe2, 10.0F);
			//GUI.DrawTexture (new Rect (Screen.height/2 + X, Screen,Width/2 + Y, Width, Height), myTexture, ScaleMode.ScaleToFit, true, 10.0f);
		}
/*
        GUIStyle toggle = GUI.skin.toggle;
        toggle.normal.textColor = Color.black;
        toggle.onNormal.textColor = Color.black;
        toggle.hover.textColor = Color.black;
        toggle.onHover.textColor = Color.black;
        */
        isToolTips = GUI.Toggle(new Rect(Screen.width / toolTipLoc.x, Screen.height / toolTipLoc.y, Screen.width / toolTipLoc.width, Screen.height / toolTipLoc.height), isToolTips, toolTipText, style);
        //GUI.skin.toggle.active = null;
        isSound = GUI.Toggle(new Rect(Screen.width / soundLoc.x, Screen.height / soundLoc.y, Screen.width / soundLoc.width, Screen.height / soundLoc.height), isSound, "", soundStyle);
        Manager.Sound = isSound;
        if(GUI.Button(new Rect(Screen.width / creditsLoc.x, Screen.height / creditsLoc.y, Screen.width / creditsLoc.width, Screen.height / creditsLoc.height),creditsText, creditsStyle))
        {
            Application.LoadLevel(5);
        }
    }



    
}
